﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.eBoss.Data.HelperClasses;
using NetDon.eBoss.Portal;
using NetDon.eBoss.Portal.Common;
using NetDon.eBoss.Portal.Constants;
using SD.LLBLGen.Pro.ORMSupportClasses;
using ServiceContainer = NetDon.Utilities.ServiceContainer;

namespace NetDon.OA.Portal.Admin
{
    [Command(ButtonConstants.CommandNames.Save, ButtonConstants.CommandImages.Save, Order = 1)]
    [Function("Admin.Configuration")]
    [Navigation("系统管理", "系统配置")]
    public partial class Configuration : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtTransportationPrefix.Text = SystemConfiguration.DefaultTransportationPrefix(CurrentApplicationContext.CompanyId);
               
            }
        }
        protected override void OnCommand(CommandEventArgs args)
        {
            if (args.CommandName == ButtonConstants.CommandNames.Save)
            {
                SaveConfigurations();

            }
            base.OnCommand(args);
        }

        protected void SaveConfigurations()
        {
            ITransaction transaction = new Transaction(IsolationLevel.ReadCommitted, "Save Configuration");
            try
            {
                var service = ServiceContainer.GetService<IConfigurationManageService>();
                var configurations = new NameValueCollection
                                         {
                                             {SystemConfiguration.TransportationPrefix, txtTransportationPrefix.Text},
                                        
                                              
                                         };
                service.SaveConfigurations(new ConfigurationManageData(){ AreaId = CurrentApplicationContext.CompanyId, NameValueCollection =configurations}, transaction);
                transaction.Commit();
            
                Success("配置保存成功！");
                return;
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
        }
    }
}